/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fmsactionserver.server;

import fmsactionserver.server.logger.InputLogger;
import fmsactionserver.server.shareserver.ShareCommand;
import fmsactionserver.server.shareserver.ShareCommandType;
import fmsactionserver.server.shareserver.SingleClientShareThread;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author rbs
 */
public class ShareServer {

    public ShareServer(InputLogger logger) throws IOException {
        
        ServerSocket server = new ServerSocket(11202);
        System.out.println("Starting Share-Server");
        while(true)
        {
            Socket client = server.accept();
            BufferedReader bufferedReader = new BufferedReader (new InputStreamReader(client.getInputStream()));
            System.out.println("Connected.");
            String version = bufferedReader.readLine();
            System.out.println("Client with version " +  version + " has connected.");
            String commandString = bufferedReader.readLine();
            System.out.println("Client sends command: " + commandString);
            ShareCommand command = new ShareCommand(commandString);
            new SingleClientShareThread(client, command, logger).start();
        }
    }
    
}
